home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX Base Documentation 1998 November
/
IRIX 6.5.2 Base Documentation November 1998.img
/
usr
/
share
/
catman
/
p_man
/
cat3s
/
popen.z
/
popen
Wrap
Text File
|
1998-10-20
|
6KB
|
133 lines
PPPPOOOOPPPPEEEENNNN((((3333SSSS)))) PPPPOOOOPPPPEEEENNNN((((3333SSSS))))
NNNNAAAAMMMMEEEE
popen, pclose - initiate pipe to/from a process
SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
####iiiinnnncccclllluuuuddddeeee <<<<ssssttttddddiiiioooo....hhhh>>>>
FFFFIIIILLLLEEEE ****ppppooooppppeeeennnn ((((ccccoooonnnnsssstttt cccchhhhaaaarrrr ****ccccoooommmmmmmmaaaannnndddd,,,, ccccoooonnnnsssstttt cccchhhhaaaarrrr ****ttttyyyyppppeeee))));;;;
iiiinnnntttt ppppcccclllloooosssseeee ((((FFFFIIIILLLLEEEE ****ssssttttrrrreeeeaaaammmm))));;;;
DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
_p_o_p_e_n creates a pipe between the calling program and the command to be
executed. The arguments to _p_o_p_e_n are pointers to null-terminated
strings. _C_o_m_m_a_n_d consists of a shell command line. _T_y_p_e is an I/O mode,
either rrrr for reading or wwww for writing. The value returned is a stream
pointer such that one can write to the standard input of the command, if
the I/O mode is wwww, by writing to the file _s_t_r_e_a_m; and one can read from
the standard output of the command, if the I/O mode is rrrr, by reading from
the file _s_t_r_e_a_m.
A stream opened by _p_o_p_e_n should be closed by _p_c_l_o_s_e, which waits for the
associated process to terminate and returns the exit status of the
command.
Because open files are shared, a type rrrr command may be used as an input
filter and a type wwww as an output filter.
EEEEXXXXAAAAMMMMPPPPLLLLEEEE
A typical call may be:
_####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_iiii_oooo_...._hhhh_>>>>
_####_iiii_nnnn_cccc_llll_uuuu_dddd_eeee _<<<<_ssss_tttt_dddd_llll_iiii_bbbb_...._hhhh_>>>>
_mmmm_aaaa_iiii_nnnn_((((_))))
_{{{{
_cccc_hhhh_aaaa_rrrr _****_cccc_mmmm_dddd _==== _""""_////_uuuu_ssss_rrrr_////_bbbb_iiii_nnnn_////_llll_ssss _****_...._cccc_""""_;;;;
_cccc_hhhh_aaaa_rrrr _bbbb_uuuu_ffff_[[[[_BBBB_UUUU_FFFF_SSSS_IIII_ZZZZ_]]]]_;;;;
_FFFF_IIII_LLLL_EEEE _****_pppp_tttt_rrrr_;;;;
_iiii_ffff _((((_((((_pppp_tttt_rrrr _==== _pppp_oooo_pppp_eeee_nnnn_((((_cccc_mmmm_dddd_,,,, _""""_rrrr_""""_))))_)))) _!!!!_==== _NNNN_UUUU_LLLL_LLLL_))))
_wwww_hhhh_iiii_llll_eeee _((((_ffff_gggg_eeee_tttt_ssss_((((_bbbb_uuuu_ffff_,,,, _BBBB_UUUU_FFFF_SSSS_IIII_ZZZZ_,,,, _pppp_tttt_rrrr_)))) _!!!!_==== _NNNN_UUUU_LLLL_LLLL_))))
_((((_vvvv_oooo_iiii_dddd_)))) _pppp_rrrr_iiii_nnnn_tttt_ffff_((((_""""_%%%%_ssss_""""_,,,, _bbbb_uuuu_ffff_))))_;;;;
_rrrr_eeee_tttt_uuuu_rrrr_nnnn _0000_;;;;
_}}}}
This will print in _s_t_d_o_u_t [see _s_t_d_i_o (3S)] all the file names in the
current directory that have a ``.c'' suffix.
SSSSEEEEEEEE AAAALLLLSSSSOOOO
pipe(2), wait(2), fclose(3S), fopen(3S), stdio(3S), system(3S).
PPPPaaaaggggeeee 1111
PPPPOOOOPPPPEEEENNNN((((3333SSSS)))) PPPPOOOOPPPPEEEENNNN((((3333SSSS))))
DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
_p_o_p_e_n returns a NULL pointer if files or processes cannot be created.
_P_c_l_o_s_e returns -1 if _s_t_r_e_a_m is not associated with a ``_p_o_p_e_ned'' command.
WWWWAAAARRRRNNNNIIIINNNNGGGG
If the original and ``_p_o_p_e_ned'' processes concurrently read or write a
common file, neither should use buffered I/O, because the buffering gets
all mixed up. Problems with an output filter may be forestalled by
careful buffer flushing, e.g. with _f_f_l_u_s_h [see _f_c_l_o_s_e(3S)].
Full pathnames should be used (or reset PATH variable) and the IFS
environment variable should be set to space and tab("\_t") to avoid
possible security problems. It should be noted that these environment
variables are inherited from the parent process.
PPPPaaaaggggeeee 2222